# coding: utf-8
from sqlalchemy import Column, DateTime, Integer, String
from sqlalchemy.schema import FetchedValue
from flask_sqlalchemy import SQLAlchemy
from common.models.department import Department
from common.models.user_tag import UserTag

from application import db


class User(db.Model):
    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    email = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    idcardnum = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    status = db.Column(db.Integer, server_default=db.FetchedValue(), info='1pass')

    depid = db.Column(db.Integer, db.ForeignKey('department.id'))
    dingtalkdepid = db.Column(db.String(255, 'utf8mb4_0900_ai_ci'))
    dingtalkmobile = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    department = db.relationship('Department', foreign_keys=depid)


    mobile = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))

    role = db.Column(db.Integer)
    hrrange= db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))

    tag = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'), db.ForeignKey('user_tag.id'))

    tagname = db.relationship('UserTag', foreign_keys=tag)
    keyinfo = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))

    post = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    postclass = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    posttype = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))

    contract_start = db.Column(db.DateTime)

    contract_end = db.Column(db.DateTime)
    contract_type = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    employdate = db.Column(db.DateTime)

    hobby = db.Column(db.String(100, 'utf8mb4_0900_ai_ci'))
    marry = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    nation = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    address = db.Column(db.String(255, 'utf8mb4_0900_ai_ci'))
    sex = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    political = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    tall = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    blood = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    userid = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    jiguan = db.Column(db.String(100, 'utf8mb4_0900_ai_ci'))
    title = db.Column(db.String(100, 'utf8mb4_0900_ai_ci'))
    pq = db.Column(db.String(255, 'utf8mb4_0900_ai_ci'))
    ec = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    ecname = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    ecmobile = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))

    contract_long = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    contract_body = db.Column(db.String(50, 'utf8mb4_0900_ai_ci'))
    workplace = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    isss = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    user_group = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    weight = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    salary=db.Column(db.Integer)



    interviewdate = db.Column(db.DateTime)
    inductiondate =db.Column(db.DateTime)
    workdate = db.Column(db.DateTime)

    idcardaddress = db.Column(db.String(255, 'utf8mb4_0900_ai_ci'))

    updated_time = db.Column(db.DateTime)
    created_time = db.Column(db.DateTime)

    # work_list = db.relationship('WorkList', backref='user')
    # # work_list = db.relationship('WorkList', primaryjoin="or_(User.id==WorkList.createuid, User.id==WorkList.uid)",
    # #                           lazy='dynamic')
    # # repr()方法显示一个可读字符串
    def __repr__(self):
        return '%s' % self.name
